home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / OpenSSL / tsafe.py < prev    next >
Text File  |  2009-01-30  |  992b  |  29 lines

  1. from OpenSSL import SSL
  2. _ssl = SSL
  3. del SSL
  4.  
  5. import threading
  6. _RLock = threading.RLock
  7. del threading
  8.  
  9. class Connection:
  10.     def __init__(self, *args):
  11.         self._ssl_conn = apply(_ssl.Connection, args)
  12.         self._lock = _RLock()
  13.  
  14.     for f in ('get_context', 'pending', 'send', 'write', 'recv', 'read',
  15.               'renegotiate', 'bind', 'listen', 'connect', 'accept',
  16.               'setblocking', 'fileno', 'shutdown', 'close', 'get_cipher_list',
  17.               'getpeername', 'getsockname', 'getsockopt', 'setsockopt',
  18.               'makefile', 'get_app_data', 'set_app_data', 'state_string',
  19.               'sock_shutdown', 'get_peer_certificate', 'want_read',
  20.               'want_write', 'set_connect_state', 'set_accept_state',
  21.               'connect_ex', 'sendall'):
  22.         exec """def %s(self, *args):
  23.             self._lock.acquire()
  24.             try:
  25.                 return apply(self._ssl_conn.%s, args)
  26.             finally:
  27.                 self._lock.release()\n""" % (f, f)
  28.  
  29.